<!-- Phan khai bao bien cuc bo-->
<?php
$v_record_id = 0;
if(isset($_REQUEST['hdn_record_id'])){
	$v_record_id = intval($_REQUEST['hdn_record_id']);
}
$v_fisrt= 0;
if(isset($_REQUEST['hdn_fisrt'])){
	$v_fisrt= $_REQUEST['hdn_fisrt']; 
}
if ($v_record_doc_id >0) {
	$v_record_doc_id = _replace_bad_char($arr_single_record_doc['PK_RECORD_DOC']);
	$v_name = _replace_bad_char($arr_single_record_doc['C_NAME']);
	$v_code = $arr_single_record_doc['C_CODE'];
	$v_promulgate = _replace_bad_char($arr_single_record_doc['C_ISSUE_AGENCY']);
	$v_date = _yyyymmdd_to_ddmmyyyy($arr_single_record_doc['C_DATE']); 
	$v_content = _replace_bad_char($arr_single_record_doc['C_CONTENT']); 
	$v_file_name = _replace_bad_char($arr_single_record_doc['C_FILE_NAME']);
}else{
	$v_record_doc_id = 0;
	$v_date = date('d/m/Y');
	$v_content = "";
	$v_code = "";
	$v_file_name = "";
}
$v_staff_id = $_SESSION['staff_id'];
$v_current_status = ($arr_single_record['C_CURRENT_STATUS']);
$v_detail_status = intval($arr_single_record['C_DETAIL_STATUS']);
//Kiem tra NSD hien thoi dong vai tro la thu ly chinh hoac nguoi phoi hop thu ly doi voi ho so hien thoi va trang thai cua ho so la "DANG_THU_LY" va C_DETAIL_STATUS <>20
if ( ((onegate_is_main_handler_for_record($v_staff_id,$v_record_id))|| (onegate_is_co_handler_for_record($v_staff_id,$v_record_id)) )&&  ($v_current_status == "DANG_THU_LY") && ($v_detail_status <> 20)){
	$v_is_main_or_co_handler_for_record_and_status = 1;
}else{
	$v_is_main_or_co_handler_for_record_and_status = 0;
}

//Doan nay dung de tao bo editor DEV-EDITOR
	SetDevEditPath($DEVEDIT_PATH, $DEVEDIT_PATH_FULL	);
	$short_des = new DevEdit();
	$short_des->SetName("txt_detail");
	$short_des->SetLanguage(DE_AMERICAN);
	$short_des->SetPathType(DE_PATH_TYPE_ABSOLUTE);
	$short_des->SetDocumentType(DE_DOC_TYPE_SNIPPET);
	$short_des->EnableGuidelines();
	$short_des->SetTextAreaDimensions("100%","100%");
	$short_des->HideSaveButton();
	//$short_des->SetValue(html_entity_decode( $v_content));
	$short_des->SetValue(( _replace_bad_char($v_content)));

$v_file_url = trim(CONST_URL_PATH_FROM_ROOT) . $v_file_name;
$v_goto_url = "javascript:filename_onclick('T_ONEGATE_RECORD_DOC', 'PK_RECORD_DOC', 'C_FILE_NAME', 'C_FILE_CONTENT'," . strval($v_record_doc_id) . ",'" . $v_file_url ."');" ;

// Goi thu tuc de them moi dong
$v_goto_url_for_add_file = "javascript:add_row(document.all.tr_line_new," . CONST_QA_FILE_MAXLENGTH .");";
$v_url = "index.php";
?>
<!-- Bat cac phim: F12=true; Insert=false; Delete=false, ESC=true; Enter=true -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(true,false,false,true,true);">
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td class="large_title" width="100%"><?php echo CONST_RECORD_DOC_DETAIL_TITLE;?>
		</td>
	</tr>	
</table>
<!--bang chua cac text box de nhap du lieu-->
<table width="100%" class="form_table1" border="0" cellpadding="0" cellspacing="0">
	<col width="20%"><col width="30%"><col width="20%"><col width="30%">
	<tr>
		<form action="index.php" method="post" enctype= "multipart/form-data" name="f_dsp_single_record_doc">
		<input type="hidden" name="fuseaction" value="UPDATE_RECORD_DOC" >	
		<input type="hidden" name="hdn_record_doc_id"  value="<?php echo $v_record_doc_id; ?>">
		<input type="hidden" name="hdn_code"  value="<?php echo $v_code; ?>">
		<input type="hidden" name="hdn_name"  value="<?php echo $v_name; ?>">
		<input type="hidden" name="hdn_promulgate"  value="<?php echo $v_promulgate; ?>">
		<input type="hidden" name="hdn_file_name"  value="<?php echo $v_file_name; ?>">
		<input type="hidden" name="hdn_fisrt" value="<?php echo $v_fisrt;?>">
		<input type="hidden" name="hdn_deleted_exist_file_id_list" value="">
		<input type="hidden" name="hdn_record_id"  value="<?php echo $v_record_id; ?>">
		<input type="hidden" name="hdn_recordtype_filter"  value="<?php echo $v_recordtype_filter; ?>">
	</tr>
	<!--Bang chua cac Thong tin-->
	<tr>
		<td class="normal_label"><?php echo CONST_RECORD_DOC_CODE_LABEL; ?></td>
		<td><input Name="txt_code"  type="text" class="normal_textbox" style="width:100%" value="<?php echo $v_code ?>" maxlength="<?php echo _CONST_AF_CODE_MAXLENGTH; ?>" message="<?php echo CONST_AF_ID_MESSAGE;?>" optional="<?php echo CONST_AF_ID_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
		<td class="normal_label"><?php echo CONST_RECORD_DOC_DATE_LABEL;?></td>
		<td>
			<input type="text" name="txt_date" class="normal_date_textbox" isdate="true" value="<?php echo $v_date;?>" optional="<?php echo CONST_VALID_DATE_OPTIONAL;?>" message="<?php echo CONST_VALID_DATE_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this);">
			<img src="<? echo $_ISA_IMAGE_URL_PATH;?>calendar.gif" border="0" onclick="DoCal('<?php echo $_ISA_LIB_URL_PATH; ?>isa-calendar/',document.forms(0).txt_date)" style="cursor:hand;">
		</td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_RECORD_DOC_NAME_LABEL; ?> <small class="normal_starmark">*</small></td>
		<td colspan="4"><input Name="txt_name"  type="text" class="normal_textbox" style="width:100%" value="<?php echo $v_name; ?>" message="<?php echo CONST_RECORD_DOC_NAME_MESSAGE;?>" optional="<?php echo CONST_TEXT_NAME_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_RECORD_DOC_ISSUE_AGENCY_LABEL; ?></td>
		<td colspan="4"><input Name="txt_promulgate" Type="text"  class="normal_textbox" style="width:100%" value="<?php echo $v_promulgate; ?>" maxlength="<?php echo _CONST_AF_NAME_MAXLENGTH;?>" message="<?php echo CONST_AF_NAME_MESSAGE;?>" optional="<?php echo CONST_AF_NAME_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="small_title" colspan="10"><?php echo CONST_RECORD_DOC_CONTENT_LABEL; ?></td>
	</tr>
	<tr>
		<td colspan="10"><!-- ~~~~~~~~~~~~~~~~~ ISA Editor    ~~~~~~~~~~~ -->
			<?php $short_des->ShowControl("100%", "300", $IMAGE_NEWS);	?>	
		</td>
	</tr>
	
	<!-- ~~~~~~~~~~~~~~~~~ File dinh kem   ~~~~~~~~~~~ -->

	<tr>
		<td class="small_title" colspan="10"><? echo CONST_RECORD_DOC_FILE_ATTACH_LABEL;?></td>
	</tr>
	<?php 
	$v_goto_url_for_delete_file = "javascript:delete_row(document.all.tr_line_exist,document.f_dsp_single_record_doc.chk_file_attach_exist_id,document.f_dsp_single_record_doc.hdn_deleted_exist_file_id_list);";
	
	if ($v_file_name!=''){
	?>
	<tr id="tr_line_exist">
		<td class="normal_label"><a href="<? echo $v_goto_url_for_delete_file;?>" class="small_link"><? echo _CONST_DELETE_BUTTON;?></a>
	    <input type="checkbox" name="chk_file_attach_exist_id" value="<? echo $v_record_doc_id; ?>"></td>
		<td class="normal_label" align="left">
			<a href="<? echo $v_goto_url; ?>" class="normal_link"><? echo $v_file_name;?></a>
		</td>
	</tr>
	<?php } ?>
	<tr>
		<td class="normal_label"></td>
		<td colspan="5">
			<input type="file" name="file_attach" style="width:100%" class="small_textbox" message="<?php echo CONST_ATTACH_FILE_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this)">
		</td>
	</tr>
<!--bang chua cac button-->
<table width="100%" >
	<tr align="center">
		<td><?php
			if (($v_is_granted_update) 
				|| (onegate_is_receiver_for_recordtype($v_staff_id,$v_recordtype_filter,$_SESSION["recordtype"])) 
				|| ($v_is_main_or_co_handler_for_record_and_status > 0)
				//Kiem tra NSD hien thoi co quyen duoc cap nhat tien do cong viec khong?
				|| (onegate_is_permission_update_rate_of_progress_for_recordtype($v_staff_id,0,$_SESSION["recordtype"]))				
			){
				$v_url_onclick="save_info('UPDATE_RECORD_DOC');";?>
				<input type="button" name="btn_save" class="normal_button" value="<?php  echo _CONST_SAVE_BUTTON;?>" onClick="<?php echo $v_url_onclick;?>" onKeyDown="change_focus(document.forms(0),this);" ><?
			}?>
			<input type="button" value="<?php echo _CONST_BACK_BUTTON; ?>" name="btn_add" class="normal_button" onClick="btn_back_onclick('<?php echo $_GO_BACK?>');">
		</td>
	</tr>			
</table>					
</form>
</div>
<script>
//-----------Ham phuc vu cho ISA-EDITOR-------------------
function change_text(p_obj,p_value){
	p_obj.value = p_value;
}
set_focus(document.f_dsp_single_record_doc);
function save_info(p_fuseaction){
	if (verify(document.forms(0))){
		document.forms(0).fuseaction.value = p_fuseaction;
	} else {
		return;
	}
	document.forms(0).hdn_fisrt.value = eval(document.forms(0).hdn_fisrt.value) + 1;
	btn_save_onclick(p_fuseaction);
}
</script>
